
package com.leaves.modular.buspicturemanager.controller;

import cn.hutool.core.lang.Dict;
import com.leaves.core.annotion.BusinessLog;
import com.leaves.core.annotion.Permission;
import com.leaves.core.enums.LogAnnotionOpTypeEnum;
import com.leaves.core.pojo.page.PageResult;
import com.leaves.core.pojo.response.ResponseData;
import com.leaves.core.pojo.response.SuccessResponseData;
import com.leaves.modular.buspicturefabulous.param.BusPictureFabulousParam;
import com.leaves.modular.buspicturemanager.entity.BusPictureManagerDto;
import com.leaves.modular.buspicturemanager.entity.CategoryPicture;
import com.leaves.modular.buspicturemanager.param.BusPictureManagerParam;
import com.leaves.modular.buspicturemanager.service.BusPictureManagerService;
import com.leaves.sys.modular.file.param.SysFileInfoParam;
import com.leaves.sys.modular.file.service.SysFileInfoService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.multipart.MultipartFile;

/**
 * 图片控制器
 *
 * @author 寻叶人
 * @date 2022-03-27 22:05:15
 */
@RestController
@Api(tags = "图片")
public class BusPictureManagerController {

    @Resource
    private BusPictureManagerService busPictureManagerService;
    @Resource
    private SysFileInfoService sysFileInfoService;

    /***************************************后台接口start***********************************************/
    /**
     * 查询图片
     *
     * @author 寻叶人
     * @date 2022-03-27 22:05:15
     */

    @GetMapping("/busPictureManager/page")
    @BusinessLog(title = "图片_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    @ApiOperation(value = "后端查询图片分页")
    public ResponseData page(BusPictureManagerParam busPictureManagerParam) {
        return new SuccessResponseData(busPictureManagerService.page(busPictureManagerParam));
    }


    /**
     * 删除图片，可批量删除
     *
     * @author 寻叶人
     * @date 2022-03-27 22:05:15
     */

    @PostMapping("/busPictureManager/delete")
    @BusinessLog(title = "图片_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    @ApiOperation(value = "后端删除图片")
    public ResponseData delete(@RequestBody @Validated(BusPictureManagerParam.delete.class) List<BusPictureManagerParam> busPictureManagerParamList) {
        busPictureManagerService.delete(busPictureManagerParamList);
        return new SuccessResponseData();
    }
    /***************************************后台接口end***********************************************/



    /***************************************app接口start***********************************************/

    /**
     * 保存图片
     *
     * @author 寻叶人
     * @date 2022-03-27 22:05:15
     */

    @PostMapping("/busPictureManager/save")
    @BusinessLog(title = "保存图片", opType = LogAnnotionOpTypeEnum.ADD)
    @ApiOperation(value = "App保存图片")
    public ResponseData save(@RequestBody @Validated(BusPictureManagerParam.save.class) BusPictureManagerParam busPictureManagerParam) {
        busPictureManagerService.save(busPictureManagerParam);
        return new SuccessResponseData();
    }

    /**
     * 上传文件
     *
     * @author yubaoshan
     * @date 2020/6/7 22:15
     */
    @PostMapping("/busPictureManager/upload")
    @BusinessLog(title = "文件信息表_上传文件", opType = LogAnnotionOpTypeEnum.OTHER)
    @ApiOperation(value = "App上传图片")
    public ResponseData upload(@RequestPart("file") MultipartFile file, SysFileInfoParam sysFileInfoParam) {
        Long fileId = sysFileInfoService.uploadFile(file, sysFileInfoParam);
        return new SuccessResponseData(fileId);
    }


    /**
     * 下载文件
     *
     * @author yubaoshan, xuyuxiang
     * @date 2020/6/9 21:53
     */

    @GetMapping("/busPictureManager/download")
    @ApiOperation(value = "App下载图片")
    @BusinessLog(title = "文件信息表_下载文件", opType = LogAnnotionOpTypeEnum.OTHER)
    public void download(@Validated(SysFileInfoParam.detail.class) SysFileInfoParam sysFileInfoParam, HttpServletResponse response) {
        sysFileInfoService.download(sysFileInfoParam, response);
    }


    /**
     * 文件预览
     *
     * @author yubaoshan, xuyuxiang
     * @date 2020/6/9 22:07
     */

    @GetMapping("/busPictureManager/preview")
    @ApiOperation(value = "App图片预览")
    public void preview(@Validated(SysFileInfoParam.detail.class) SysFileInfoParam sysFileInfoParam, HttpServletResponse response) {
        sysFileInfoService.preview(sysFileInfoParam, response);
    }

    /**
     * 查看详情文件信息表
     *
     * @author yubaoshan
     * @date 2020/6/7 22:15
     */

    @GetMapping("/busPictureManager/fileDetail")
    @BusinessLog(title = "文件信息表_查看详情", opType = LogAnnotionOpTypeEnum.DETAIL)
    @ApiOperation(value = "App查看图片详情")
    public ResponseData detail(@Validated(SysFileInfoParam.detail.class) SysFileInfoParam sysFileInfoParam) {
        return new SuccessResponseData(sysFileInfoService.detail(sysFileInfoParam));
    }


    /**
     * 获取图片类型
     *
     * @author yubaoshan
     * @date 2020/6/7 22:15
     */

    @GetMapping("/busPictureManager/getPictureType")
    @ApiOperation(value = "App图片类型")
    @BusinessLog(title = "获取图片类型", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getPictureType() {
        List<Dict> list = busPictureManagerService.getPictureType();
        return new SuccessResponseData(list);
    }

    /**
     * 获取banner图片
     *
     * @author yubaoshan
     * @date 2020/6/7 22:15
     */

    @GetMapping("/busPictureManager/getBanners")
    @ApiOperation(value = "Appbanner图片")
    @BusinessLog(title = "获取banner图片", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData getBanners() {
        List<BusPictureManagerDto> list = busPictureManagerService.getBanners();
        return new SuccessResponseData(list);
    }

    /**
     * 分类图片
     * @return
     */
    @GetMapping("/busPictureManager/categoryPicture")
    @ApiOperation(value = "App分类图片")
    @BusinessLog(title = "分类图片", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData categoryPicture() {
        List<CategoryPicture> list = busPictureManagerService.categoryPicture();
        return new SuccessResponseData(list);
    }

    /**
     * 图片查询
     * @return
     */
    @GetMapping("/busPictureManager/searchCategoryPicture")
    @ApiOperation(value = "App图片查询")
    @BusinessLog(title = "图片查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData singleCategoryPicture(@Validated(BusPictureManagerParam.singleCategory.class) BusPictureManagerParam busPictureManagerParam) {
        return new SuccessResponseData(busPictureManagerService.searchCategoryPicture(busPictureManagerParam));
    }

    /**
     *作品点赞
     */
    @PostMapping("/busPictureManager/pictureFabulous")
    @ApiOperation(value = "作品点赞")
    public ResponseData pictureFabulous(@RequestBody @Validated(BusPictureFabulousParam.fabulous.class) BusPictureFabulousParam busPictureFabulousParam) {
        busPictureManagerService.pictureFabulous(busPictureFabulousParam);
        return new SuccessResponseData();
    }
}
